from odoo import api, fields, models


class HostelBook(models.Model):
    _name = 'hostel.book'
    _description = 'Hostel Book'
    _inherits = {'res.partner': 'partner_id'}
    
    partner_id = fields.Many2one('res.partner', string='Partner', required=True, ondelete='cascade')

    is_hostel_rector = fields.Boolean(string="Is Hostel Rector", 
                                    help="Check if this partner is a hostel rector")
    assign_room_ids = fields.Many2many('hostel.room', string="Assigned Rooms",
                                     help="Rooms assigned to this hostel rector")
    count_assign_room = fields.Integer(string="Assigned Rooms Count",
                                     compute='_compute_count_assign_room',
                                     help="Number of rooms assigned to this rector")

    @api.depends('assign_room_ids')
    def _compute_count_assign_room(self):
        for record in self:
            record.count_assign_room = len(record.assign_room_ids)
